﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZLCMS.Business.DwzFrame;
using NHibernate;
using ZLCMS.Business;
using ZLCMS.Business.Util;

namespace ZLCMS.Web.SystemManage.weixin.MessageRecord
{
    public partial class MessageRecordDelete : System.Web.UI.Page
    {
        protected string _userAccount;

        protected void Page_Load(object sender, EventArgs e)
        {
            _userAccount = UserKit.GetUserAccountFailLogin();
            
            FrameHelper framePage = new FrameHelper(this);
            string ids = Request["ids"];
            if (!string.IsNullOrEmpty(ids))
            {
                string[] idStrs = ids.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                IList<int> idList = new List<int>();
                foreach (string acc in idStrs)
                {
                    if (!string.IsNullOrEmpty(acc))
                    {
                        idList.Add(Int32.Parse(acc));
                    }
                }
                using (ISession session = DotNet.Common.NHibernateUtil.SessionFactoryHelper.CreateSession())
                {
                    session.CreateSQLQuery("delete from WX_MESSAGE_RECORD where id in (:ids) and owner_account=:acc")
                        .SetParameter("acc", _userAccount)
                        .SetParameterList("ids", idList.ToArray())
                        .ExecuteUpdate();
                    session.Flush();
                    framePage.Alert(new ReturnCode() { statusCode = 200, message = "操作成功!", navTabId = framePage.NavTabId });
                }
            }
            else
            {
                framePage.Alert(new ReturnCode() { statusCode = 300, message = "参数错误" });
            }
        }
    }
}